﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MCB.Net.Protocol
{
    public class ProtocolProcessor
    {
        protected List<IProtocolFactory> _factories = new List<IProtocolFactory>();

        public ProtocolProcessor()
        {
            AddProtocol(new HttpProtocolFactory());
        }

        public void AddProtocol(IProtocolFactory factory)
        {
            _factories.Add(factory);
        }

        public IProtocol GetProtocol(byte[] buffer)
        {
            foreach (IProtocolFactory factory in _factories)
            {
                IProtocol protocol = factory.GetProtocol(buffer);

                return (protocol != null) ? protocol : null;
            }
            return null;
        }
    }
}
